// 引入
import http from "./request";
// 登陆
export const getLogin = (msg) => {
    let data = http.post('/login', msg)
    return data
}
// 侧边导航
export const getMenus = (msg) => {
    let data = http.get('/menus', msg)
    return data
}
// 渲染用户列表
export const getUsers = (params) => http.get('/users', { params })
// 添加用户列表
const usersAdd = (params) => {
    return http.post('/users', params)
}

// 删除用户列表
const del = (params) => {
    console.log(params)
    return http.delete(`users/${params.id}`, params)
}
// 编辑
const edit = (params) => {
    console.log(params)
    return http.put(`users/${params.id}`, params)
}
// 根据 ID 查询角色
const Charoles = (params) => {
    return http.get(`roles/${params.id}`, params)
}

// 修改状态
const userId = (params) => {
    return http.put(`users/${params.uld}/state/${params.type}`)
}
//修改
const getRoles = (msg) => {
    let data = http.get('/roles', msg)
    return data
}

// 修改权限
const editqx = (msg) => {
     return http.put(`users/${msg.id}/role`, msg)
    }
    
//填加角色
const addrole = (msg) => {
    let data = http.post('/roles', { roleName: msg.roleName, roleDesc: msg.roleDesc })
    return data
}
//编辑角色
const editrole = (msg) => {
    let data = http({
        url: `roles/${msg.id}`, 
        data: { roleName: msg.roleName, roleDesc: msg.roleDesc }, 
        method: 'put'
    })
    return data
}
//删除角色
const delrole = (msg) => {
    let data = http({ url: `roles/${msg}`, method: 'delete' })
    return data
}
//根据id删除角色({roleId:角色id,rightId:权限id})
const delroleById = (msg) => {
    let data = http({ url: `roles/${msg.roleId}/rights/${msg.rightId}`, method: 'delete' })
    return data
}

//所有权限列表
const allrights = (msg) => {
    let data = http.get(`rights/${msg}`)
    return data
}
//更新角色授权updaterole({id:"",rids:""})
const updaterole = (msg) => {
    let data = http.post(`roles/${msg.id}/rights`, { rids: msg.rids })
    return data
}
//订单数据

export const getOrders = (params) => {
    let data = http.get('/orders', { params })
    return data
}
// 商品列表
export const getgoods = (params) => {
    let data = http.get('/goods', { params })
    return data
}
// 添加商品列表
export const addgoods = (params) => {
    let data = http.post('/goods', params)
    return data
}
export const attrlist = (msg) => {
    let data = http.get(`categories/${msg.id}/attributes`, { params: { sel: msg.sel } })
    return data
}
//商品分类
export const getCategories = (params) => {
    let data = http.get('/categories', { params })
    return data
}
export const reportlist = (params) => {
    let data = http.get('/reports/type/1', params)
    return data
}
export const getCategories2 = (params) => {
    let data = http.get(`/categories/${params.id}/attributes`, { params })
    return data
}

// 添加动态参数或静态属性
export const addCategories = (params) => {
    let data = http.post(`/categories/${params.id}/attributes`,params)
    return data
}
// 编辑提交参数
export const editCategories = (msg) => {
    let data = http({ url: `categories/${msg.id}/attributes/${msg.attrId}`, method: 'put' })
    return data
}
// 删除
export const delCategories = (msg) => {
    let data = http({ url: `categories/${msg.id}/attributes/${msg.attrId}`, method: 'delete' })
    return data
}

// 删除商品列表
export const delgoods = (params) => {
    console.log(params)
    return http.delete(`goods/${params.id}`, params)
}
// 删除商品分类数据列表
export const delcategories = (msg) => {
    let data = http({ url: `categories/${msg.id}`, method: 'delete' })
    return data
}
// 添加
export const getCategoriesAdd = (params) => {
    return http.post(`categories`, params)
}
// 编辑
export const getCategoriesEdit = (params) => {
    return http.put(`categories/${params.id}`, { cat_name: params.cat_name })
}


export { del, usersAdd, Charoles, userId, edit, getRoles,editqx, addrole, editrole, delrole, delroleById, allrights, updaterole }





